package com.aaa.ssm.controller;

import com.aaa.ssm.entity.Role;
import com.aaa.ssm.service.RoleService;
import com.aaa.ssm.util.Page;
import com.aaa.ssm.util.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/role")
public class RoleController extends BaseController{
  @Resource //依赖注入
    private RoleService roleService;

  /**
   * 查询启用职位(添加员工时,下拉使用)
   * @return
   */
  @GetMapping("queryAll")
  public Result queryAll(){
    return success(roleService.queryAll());
  }

  /**
   * 获取所有的角色
   * @return 角色和角色id
   */
  @GetMapping("queryIdAll")
  public Result queryIdAll(){
    return success(roleService.queryIdAll());
  }

  /**
   * 根据参数实现分页查询
   * @param page
   * @return
   */
  @PostMapping("queryPage")
    public Result queryPage(@RequestBody Page<Role> page){
      return success(roleService.queryPage(page));
  }

  /**
   * 根据角色ID查询该角色关联的所有权限ID集合
   * @param roleId
   * @return
   */
  @GetMapping("queryMenuIdListByRid")
  public Result queryMenuIdListById(Integer roleId){
    return success(roleService.queryMenuIdListByRid(roleId));
  }

  /**
   * 添加角色权限关联
   * @param roleId
   * @param menuIds
   * @return
   */
  @PostMapping("addPosAndMenu")
  public Result addPosAndMenu(Integer roleId, String menuIds){
    return success(roleService.addPosAndMenu(roleId,menuIds));
  }

  /**
   * 给根据编号查询
   * @param roleId
   * @return
   */
    @PostMapping("queryById")//普通属性传参 不需要加requestbody
    public Result queryById(Integer roleId){
      return success(roleService.queryById(roleId));
    }

  /**
   * 添加数据
   * @param role
   * @return
   */
  @PostMapping("add")
    public Result add(@RequestBody Role role){
      return success(roleService.add(role));
    }

  /**
   * 更新数据
   * @param role
   * @return
   */
    @PostMapping("update")
    public Result update(@RequestBody Role role){
      return success(roleService.update(role));
    }

  /**
   * 根据参数删除数据
   * @param roleId
   * @return
   */
  @PostMapping("deleteById/{roleId}")
    public Result deleteById(@PathVariable("roleId") Integer roleId){
      return success(roleService.deleteById(roleId));
    }

}
